<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>解绑旧手机号</title>
<%@ include file="/pages/wx/baseHead.jsp"%>
<link rel="stylesheet" href="<%=basePath%>/css/weixin/example.css" />
<script type="text/javascript">
	
	
	
	$(function(){
		setReadOnly("#checkCode",true);
		$(".checkCodeClass").bind( "click",function(){
			sendCode();
		});
		
		$("#checkCode").bind('input',function(){
			
			/* if($("#checkCode").val().length == 4)
			{
				$(".nexStep").removeClass("weui_btn_default");
				$(".nexStep").addClass("weui_btn_primary");
			}else
			{
				$(".nexStep").removeClass("weui_btn_primary");
				$(".nexStep").addClass("weui_btn_default");
			} */
		});
	});
	
	function doIt()
	{
		debugger;
		var checkCode = $("#checkCode").val();
		if(isNull(checkCode))
		{
			openDia('提示','请输入验证码');
			return;
		}else
		{
			var phone = '${user.phone }';
			var checkCode = $("#checkCode").val();
			var url = '${urlBasePath}weixin/isValidCode.do';
			$.ajax({
				url:url,
				async:false,
				data:{
					phone:phone,
					checkCode:checkCode,
					funcCode:'1002'
				},
				success:function(ret){
					if(ret.code == '0')
					{
						$("#theform").submit();
					}else
					{
						openDia(ret.msg);
					}
				},
				error:function(){
					
				}
			})
			
		}
	}

	var times = 120;
	function cd()
	{
		if(times == 0)//释放
		{
			$("#getCodeFont").html("获取验证码");
			setDisable(".checkCodeClass",false);
			
			$(".checkCodeClass").bind( "click",function(){
				sendCode();
			});
			return;
		}
		times--;
		$("#getCodeFont").html(times+"秒后重取");
		setTimeout("cd();",1000);
	}
	
	function sendCode()
	{
		var url = '${urlBasePath}weixin/sendCodeUnbindOld.do';
		$.ajax({
			type: 'POST',
			url:url,
			async:false,
			data:
			{
				v:new Date().getTime()
			},
			success:function(data)
			{
				if(data.code == '0')
				{
					times = 120;
					setDisable(".checkCodeClass",true);
					$(".checkCodeClass").unbind( "click");
					setReadOnly("#checkCode",false);
					openToast("验证码已发送");
					cd();
				}else
				{
					openToast(data.msg);
				}
			},
			fail:function()
			{
				alert('发送验证码失败');
			}
		});
	}
	
</script>

</head>
<body>

<div class="hd">
    <h1 class="page_title">
    	解绑旧手机<br>
    	<button class="weui_btn weui_btn_plain_primary weui_btn_mini ">1、获取验证码</button>
    	<button class="weui_btn weui_btn_plain_primary weui_btn_mini ">2、输入验证码</button>
    </h1>
</div>
<div class="weui_cells weui_cells_form">
        <div class="weui_cell">
            <div class="weui_cell_hd"><label class="weui_label" style="font-weight: normal;min-width: 4em;">手机号：</label></div>
            <div class="weui_cell_bd weui_cell_primary">
                <input class="weui_input" type="text" value="${user.phone }"  readonly="readonly" style="color: gray"/>
            </div>
            <div class="weui_cell_hd"><button class="weui_btn weui_btn_plain_primary weui_btn_mini checkCodeClass">
            	<font id="getCodeFont">获取验证码</font>
            	</div>
        </div>
        <div class="weui_cell">
            <div class="weui_cell_hd"><label class="weui_label"  style="font-weight: normal;min-width: 4em;">验证码：</label></div>
            <div class="weui_cell_bd weui_cell_primary">
            	<form action="${urlBasePath}weixin/user/toReBindPhoneNew.do" method="POST" id="theform" name = "theform">
                	<input class="weui_input" type="number" id="checkCode" maxlength="4"  name="checkCode" placeholder="请输入验证码"/>
                </form>
            </div>
        </div>
</div>

<div style="display: block;height: 20px;"></div>

<button onclick="doIt();" class="weui_btn weui_btn_primary nexStep">下一步</button> 

<div class="pop">
    <i class="fa fa-home fa-lg popi"></i>
</div>

<!-- 引入微信样式代码提示工具开始 -->
<%@ include file="/pages/wx/wxClass.jsp"%>
<!-- 引入微信样式代码提示工具结束 -->
<%@ include file="/pages/wx/baseBottom.jsp"%>
</body>
</html>

